<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 公共基础类
*/
class CommonController extends Controller{
	public  $_user_id         = '';//用户ID
	public  $_province_id     = 0;//省份ID
	public  $_city_id         = 0;//城市ID
	public  $_city_name       = '';//城市名称
	public  $_group_id        = '';//用户组
	public  $_is_supper_admin = '';//是否为超级管理员
	public  $_username        = '';//用户名
	public  $_use_tpl         = '';//添加修改使用模板
	public  $_model           = '';//当前模型
	public  $_pagesize        = '';//分页数量
	public  $_show_all_data   = false;//显示所有数据
	public  $_db_field        = '';//表字段
	public  $_db_join         = '';//关联数据库操作
	public  $_db_where        = array();//查询条件
	public  $_db_order        = 'order_id';//查询条件
	public  $_filter_field    = '';//过滤修改字段
	public  $_boolean_field   = '';//添加列表是否字段
	public  $_set_info        = '';//设置修改信息数据
	public  $_opt_tip         = '';//设置添加修改操作提示信息
	public  $_jump_url        = '';//添加修改成功后跳转URL
	public  $_notip_redirect  = false;//不提示直接跳转
	public  $_last_id_field   = '';//返回插入ID的字段
	public  $exec_comfunc     = '';//index,add,edit,delete
	public  $exec_checkfunc   = 'index,add,edit,delete,del,recycle';
	public  $viewFields       = '';//视图字段
	private $_trail           = array ();//导航数据
	private $_title           = null;//当前页面标题
	public $_cur_title        = null;//当前标题
	public $_top_menu_list    = array();//顶部菜单
	public $_left_menu_list   = array();//左侧菜单

	//该函数相当于__Construct()函数
	public function _initialize(){
		//用户信息
		$user_id = session('user_id');
		// $user_id = 1;
		if(empty($user_id) && in_array(CONTROLLER_NAME, array('Login')) == false){
			// $this->error('对不起，您未登录或登录超时！',U('Login/index'));
			redirect(U('Login/index'));
		}
		//获取用户信息
		$where['id'] = $user_id;
		$userinfo = D('Admin')->where($where)->find();
		// var_dump($userinfo);
		if($userinfo['status'] == 0 && in_array(CONTROLLER_NAME, array('Login')) == false){
			$this->error('对不起，您的账号被禁用，请联系相关人员！',U('Login/index'));
		}
		$role_model = D('Role');
		//栏目权限
		$menu_role = $role_model->menu($userinfo['role_id'], $user_id);
		//左侧菜单
		if(!$role_model->get_user_menu()){
			$this->error('对不起，您没有权限！');
		}
		$this->assign('_top_menu_list', $role_model->_top_menu_list);
		$this->assign('_left_menu_list', $role_model->_user_menu_left);

		//面包导航配置
		$this->add_step('首页',U('Index/index/'));
		//左侧选中菜单信息
		$select_info = $role_model->_select_left_menu_info;
		foreach ($select_info as $rs) {
			$this->add_step($rs['title'], U($rs['url']));
			foreach ($rs['filter_list'] as $row) {
				if($row['is_select']){
					$this->add_step($row['title'], U($row['url']));
					break;
				}
			}
		}

		$this->_user_id         = $userinfo['id'];
		$this->_city_id         = $userinfo['city_id'];
		$this->_province_id     = $userinfo['province_id'];
		$this->_username        = $userinfo['username'];
		$this->_realname        = $userinfo['realname'];
		$this->_role_id         = $userinfo['role_id'];
		$this->_is_supper_admin = $role_model->_is_supper_admin;

		if($this->_city_id){
			$this->_city_name = D('Area')->id2names($this->_city_id);
			$this->assign('_city_id',$this->_city_id);
			$this->assign('_city_name',$this->_city_name);
			$this->assign('_province_id',$this->_province_id);
		}


		//处理通用操作权限
		$exec_comfunc   = explode(',', $this->exec_comfunc);
		$exec_checkfunc = explode(',', $this->exec_checkfunc);
		if(in_array(ACTION_NAME, $exec_checkfunc)){
			if(in_array(ACTION_NAME, $exec_comfunc)==false){
				$this->error('对不起，系统尚未针对此方法配置权限！');
			}
		}

		$this->assign('type', $this->_get('type'));
		$this->assign('_user_id', $this->_user_id);
		$this->assign('_role_id', $this->_role_id);
		$this->assign('_username', $this->_username);
		$this->assign('_realname', $this->_realname);
		$this->assign('_is_supper_admin', $this->_is_supper_admin);

	}
	//操作步骤
	protected function add_step($title, $url = ''){
		$this->_title     = empty($this->_title) ? $title : $title . ' - ' . $this->_title;
		$this->_trail[]   = array('title'=>$title,'url'=>$url);
		$this->_cur_title = $title;
		return $this;
	}
	//重写页面显示
	protected function display($templateFile='',$charset='',$contentType='text/html'){
		$this->assign('_title', $this->_title);
		$this->assign('_trail', $this->_trail);
		$this->assign('_cur_title', $this->_cur_title);
		// D("Log")->write($this->_trail);
		parent::display($templateFile,$charset,$contentType);exit();
	}
	/**
	 * 重写成功操作
	 * @param  [type] $info 提示信息
	 * @param  string $url  跳转URL
	 * @param  array  $data 数据
	 */
	protected function success($info, $url = '', $data = array()){
		$json = '';
		if($data || IS_AJAX){
			$json['data'] = $data;
		}
		parent::success($info, $url, $json);
	}
	/**
	 * 重写失败操作
	 * @param  [type] $info 提示信息
	 * @param  string $url  跳转URL
	 * @param  array  $data 数据
	 */
	protected function error($info, $url = '', $data = array()){
		$json = '';
		if($data || IS_AJAX){
			$json['data'] = $data;
		}
		parent::error($info, $url, $json);
	}
	protected function json_success($info = '',$data = '',$status = 200){
		$json['data']   = $data ? $data : null;
		$json['status'] = $status;
		$json['info']   = $info;
		$json = $this->ajaxReturn($json, 'json', JSON_UNESCAPED_UNICODE);
	}
	protected function json_error($info='',$data = '',$status = 400){
		$json['data']   = $data ? $data : null;
		$json['status'] = $status;
		$json['info']   = $info;
		$json = $this->ajaxReturn($json, 'json', JSON_UNESCAPED_UNICODE);
	}
	
	
	/**
	 * GET请求处理
	 * @param  string $field         get参数名
	 * @param  string $empty_msg     get值为空，提示信息
	 * @param  string $default_value get值为空，默认值
	 * @param  string $check_type    验证类型，具体参数check模型
	 * @param  string $check_msg     验证失败返回提示信息
	 * @return [type]                返回参数值
	 */
	protected function _get($field,$empty_msg='',$default_value='',$check_type='',$check_msg=''){
		$value = trim(I('get.' . $field));
		$value = $this->common_field_check($value,$empty_msg,$default_value,$check_type,$check_msg);
		$this->assign($field, $value);

		return $value;
	}
	/**
	 * POST请求处理
	 * @param  string $field         post参数名
	 * @param  string $empty_msg     post值为空，提示信息
	 * @param  string $default_value post值为空，默认值
	 * @param  string $check_type    验证类型，具体参数check模型
	 * @param  string $check_msg     验证失败返回提示信息
	 * @return [type]                返回参数值
	 */
	protected function _post($field,$empty_msg='',$default_value='',$check_type='',$check_msg=''){
		$value = I('post.' . $field);
		$value = $this->common_field_check($value,$empty_msg,$default_value,$check_type,$check_msg);
		$this->assign($field, $value);

		return $value;
	}
	/**
	 * 通用字段验证
	 * @param  [type] $value         [description]
	 * @param  string $empty_msg     [description]
	 * @param  string $default_value [description]
	 * @param  string $check_type    [description]
	 * @param  string $check_msg     [description]
	 * @return [type]                [description]
	 */
	public function common_field_check($value,$empty_msg='',$default_value='',$check_type='',$check_msg=''){
		if(!$value&&$empty_msg){
			$this->error($empty_msg);
		}
		if(!$value){
			$value = $default_value;
		}
		return $value;
	}
	/**
	 * 通用列表
	 * @param  string  $model 模型
	 * @param  array   $where where条件
	 * @param  array   $order 排序条件
	 * @param  boolean $return 是否返回数据，返回则不输出模板
	 */
	public function index($model='', $where='', $order='', $return=false){
		//使用模型
		$model    = D($model ? $model : CONTROLLER_NAME);
		$field    = $this->_db_field ? $this->_db_field : '*';
		$join     = $this->_db_join ? $this->_db_join : '';
		$pagesize = $this->_pagesize ? $this->_pagesize : 20;
		if($this->viewFields){
			$model = D('Views');
			$model->viewFields = $this->viewFields;
		}
		$this->_model = $model;
		//使用模板
		$tpl   = $this->_use_tpl ? $this->_use_tpl : ACTION_NAME;
		//是否字段
		$boolean_field = $this->_boolean_field ? $this->_boolean_field : array('');
		// 主键KEY
		$pk_name = $model->getPk();

		//处理列表记录内容修改
		if(IS_POST){
			$listid   = $this->_post('id');
			if($listid){
				$data = '';
				$form_data = $_POST;
				foreach($listid as $id){
					foreach ($form_data as $key => $val) {
						$value = htmlspecialchars($val[$id]);
						$data[$key] = $value ? $value : '';
						if($key == 'order_id'){
							$data[$key] = $data[$key] ? $data[$key] : '999999';
						}
					}
					if($boolean_field){
						foreach ($boolean_field as $key) {
							$data[$key] = $data[$key] ? 1 : 0;
						}
					}
					// $data['status'] = $data['status']?1:0;
					unset($data['id']);
					$ewhere[$pk_name] = $id;
					$model->where($ewhere)->save($data);
					unset($ewhere);
				}
			}
		}
		$page         = $this->_get('page','',1);
		$search_field = $this->_get('search_field');
		$keyword      = $this->_get('keyword');

		//where条件
		$where = array_merge($where ? $where : array(), $this->_db_where ? $this->_db_where : array());
		if($keyword){$where[$search_field] = array('like',"%$keyword%");}
		$where['is_delete'] = 0;

		//排序条件
		$order = $order ? $order : ($this->_db_order ? $this->_db_order . ',' : '') . $pk_name . ' desc';

		// var_dump($where);exit;
		//导入分页类
		import("ORG.Util.Page");
		//获取记录数
		$count = $model->join($join)->where($where)->count();
		//显示所有数量
		if($this->_show_all_data){
			$pagesize = $count;
		}
		// var_dump($model->getLastSql());exit;
		$p = new \Think\Page($count, 25);
		$p->setConfig('prev','上一页');
		$p->setConfig('next','下一页');
		$p->setConfig('theme', C('PAGE_THEME'));

		$this->assign('count', $count);
		//导出Excel数据
		$export = $this->_get('export');
		if($export == 'excel'){
			$export_sql = $model->where($where)->order($order)->fetchSql(true)->select();
			$this->get_export_file($export_sql, $this->export_data_title);
		}
		//获取列表数据
		$list = $model->field($field)->join($join)->where($where)->limit($p->firstRow.','.$p->listRows)->order($order)->select();
		// var_dump($model->getLastSql());
		//分页写入模板
		$this->assign('page', $p->show());
		//搜索字段
		$this->assign('search_field', $search_field);
		//搜索关键字
		$this->assign('keyword', $keyword);
		//列表数据
		$this->assign('list', $list);
		$this->assign('list_count', $count);

		if($return == true){
			return $list;
		}
		$this->display($tpl);
	}
	/**
	 * 分页参数
	 * @param  [type] $count    记录总数
	 * @param  [type] $pagesize 每页数量
	 */
	protected function page_info($count, $pagesize){
		$data['page']       = $this->_get('p', '', 1);
		$data['pagesize']   = $pagesize;
		$data['total_page'] = ceil($count / $pagesize);
		$data['count']      = (int)$count;
		return $data;
	}
	protected function ajax_page($list = '', $count = 0, $tpl = '', $list_field = 'list'){
		$tpl        = $tpl ? $tpl : CONTROLLER_NAME;
		$list_field = $list_field ? $list_field : 'list';
		$page       = $this->_get('p', '', 1);
		$pagesize   = $this->pagesize ? $this->pagesize : 15;
		$total_page = ceil($count / $pagesize);
		//AJAX分页加载数据处理
		$url   = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') ? '' : "?");
		$parse = parse_url($url);
		if(isset($parse['query'])) {
			parse_str($parse['query'], $params);
			unset($params['p']);
			$url = $parse['path'] . '?' . http_build_query($params);
		}
		$ajax_next_page = $url . '&p=' . ($page + 1);
		if($page >= $total_page){
			$ajax_next_page = '';
		}
		// var_dump($page);
		// var_dump($total_page);
		// var_dump($ajax_next_page);
		$this->assign('ajax_next_page', $ajax_next_page);
		if(IS_AJAX && $page > 1){
			// var_dump($list);exit;
			$this->assign($list_field, $list);
			$data['html'] = $this->fetch($tpl . '_ajax_item');
			$data['page']['cur_page']       = $page;
			$data['page']['total_page']     = $total_page;
			$data['page']['ajax_next_page'] = $ajax_next_page;

			$this->success('获取数据成功！', '', $data);
		}
	}
	protected function get_export_file($sql='', $data_title=''){
		$data_title = json_encode($data_title);
		$md5 = md5($sql . $data_title);

		$data['data_title']  = $data_title;
		$data['sql']         = $sql;
		$data['md5']         = $md5;
		$data['create_time'] = time();

		$where['md5'] = $md5;
		$info = D('ExportData')->where($where)->find();
		if($info['status'] == 'finish'){
			header("Content-Type: application/force-download");
			header("Content-Type: application/octet-stream");
			header("Content-Type: application/download");
			header('Content-Disposition:inline;filename="' . $info['filename']);
			header("Content-Transfer-Encoding: binary");
			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
			header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Pragma: no-cache");
			echo file_get_contents('.' . $info['filepath']);
			exit;
		}
		//加入导出队列
		if(!$info){
			D('ExportData')->add($data);
		}
		$this->success('正在导出，请稍候再来！', U('ExportData/index'));
	}
	//回收站
	public function recycle($model = '', $where = ''){
		$count = count($this->_trail);
		$this->_cur_title = $this->_trail[$count - 2]['title'];
		$where['is_delete'] = 1;
		self::index('', $where, 'recycle_time desc');
	}
	/**
	 * 通用添加数据
	 * @param string $model 模型
	 * @param array  $data  自定义要添加数据
	 * @param string $url   操作成功跳转URL
	 */
	public function add($model='',$data='',$jump_url=''){
		$data  = $data?$data:array();
		//使用模型
		$model = D($model?$model:CONTROLLER_NAME);
		//使用模板
		$tpl   = $this->_use_tpl ? $this->_use_tpl : 'edit';
		
		$type  = $this->_get('type');
		//操作成功跳转URL
		$jump_url = $jump_url ? $jump_url : ($this->_jump_url ? $this->_jump_url : U('index', array('type' => $type)));

		//表单提交处理
		if(IS_POST){
			if($form_data = $model->create()){
				//插入创建时间
				$form_data['create_time'] = time();
				$form_data['edit_time']   = time();
				$form_data['admin_id']    = $this->_user_id;
				//合并表单及自定义字段
				$newdata = array_merge($form_data,$data);
				//处理数组字段成按逗号分隔字符串
				foreach ($newdata as $key => $value) {
					if(is_array($value)){
						$value = implode(',', $value);
						if(substr($value, 0, 2) == '0,'){
							$value = substr($value, 2);
						}
					}
					$new_data[$key] = htmlspecialchars_decode($value);
				}
				unset($new_data['id']);
				if(false !==$model->add($new_data)) {
					$last_id = $model->getLastInsID();
					if($this->_last_id_field && $last_id){
						$jump_url = $jump_url . '?' . $this->_last_id_field . '=' . $last_id;
					}
					if($this->_notip_redirect){
						redirect($jump_url);
					}else{
						$this->success($this->_opt_tip?$this->_opt_tip:'添加成功！',$jump_url);
					}
				}else{
					$this->error($this->_opt_tip?$this->_opt_tip:'添加失败！');
				}
			}else{
				$this->error($model->getError());
			}
		}
		$info['province_id'] = '';
		$info['city_id']     = '';
		$this->assign('info', $info);
		$this->display($tpl);
	}
	/**
	 * 通用修改数据
	 * @param  string $model 模型
	 * @param  array  $data  自定义数据
	 * @param  int    $id    修改ID
	 * @param  string $url   操作成功跳转URL
	 */
	public function edit($model = '', $data = '', $jump_url = ''){
		$data = $data?$data:array();

		//使用模型
		$model = D($model ? $model : CONTROLLER_NAME);
		//使用模板
		$tpl   = $this->_use_tpl ? $this->_use_tpl : ACTION_NAME;
		//过滤修改字段
		$filter_field = $this->_filter_field ? $this->_filter_field : '';
		$where        = $this->_db_where ? $this->_db_where : '';
		//修改ID
		$pk_name = $model->getPk();
		$id = $this->_get($pk_name ? $pk_name : 'id', '对不起，ID不能为空');
		// 主键KEY
		if($pk_name){
			$where[$pk_name] = $id;
		}

		$type  = $this->_get('type');
		//操作成功跳转URL
		$jump_url = $jump_url ? $jump_url : ($this->_jump_url ? $this->_jump_url : U('index', array('type' => $type)));

		if(IS_POST){
			if($form_data = $model->create()){
				//更新修改时间
				$form_data['edit_time'] = time();
				//合并表单及自定义字段
				$newdata = array_merge($form_data, $data);
				//处理数组字段成按逗号分隔字符串
				foreach ($newdata as $key => $value) {
					if(is_array($value)){
						$value = implode(',', $value);
						if(substr($value, 0, 2) == '0,'){
							$value = substr($value, 2);
						}
					}
					$new_data[$key] = htmlspecialchars_decode($value);
				}
				//过滤不修改字段
				if($filter_field){
					foreach ($filter_field as $field) {
						unset($new_data[$field]);
					}
				}
				if(false !==$model->where($where)->save($new_data)) {
					if($this->_notip_redirect){
						redirect($jump_url);
					}else{
						$this->success('修改成功！', $jump_url);
					}
				}else{
					$this->error('修改失败！');
				}
			}else{
				$this->error($model->getError());
			}
		}
		//获取数据
		$info = $model->where($where)->find($id);
		//整合外部数据
		$set_info = $this->_set_info ? $this->_set_info : array();
		$new_info = array_merge($info, $set_info);
		// var_dump($new_info);

		$this->assign('info', $new_info);
		$this->display($tpl);
	}
	/**
	 * 通用删除
	 * @param  string $model 模型
	 */
	public function delete($model='', $did=''){
		$id    = $did ? $did : $this->_get('id');
		$ids   = $this->_post('ids');
		$where = $this->_db_where ? $this->_db_where : '';
		
		//使用模型
		$model = D($model ? $model : CONTROLLER_NAME);
		// 主键KEY
		$pk_name = $model->getPk();
		if(!is_array($ids) && $id){
			$where[$pk_name] = $id;
			if($model->where($where)->delete()==true){
				$this->success('删除成功!');
			}else{
				$this->error('删除失败!');
			}
		}
		elseif(is_array($ids)){
			$ids             = implode(',', $ids);
			$where[$pk_name] = array('in', $ids);

			$model->where($where)->delete();
			$this->success('批量删除成功!');
		}else{
			$this->error('请选择要删除内容!');
		}
	}
	/**
	 * 虚拟删除
	 * @param  string $model [description]
	 * @param  string $did   [description]
	 * @return [type]        [description]
	 */
	public function del($model = '',$did = ''){
		//使用模型
		$model   = D($model ? $model : CONTROLLER_NAME);
		// 主键KEY
		$pk_name = $model->getPk();
		
		$id    = $did ? $did : $this->_get($pk_name ? $pk_name : 'id');
		$ids   = $this->_post('ids');
		$where = $this->_db_where ? $this->_db_where : '';
		
		$data['is_delete']    = 1;
		$data['recycle_time'] = time();
		if(!is_array($ids) && $id){
			$where[$pk_name] = $id;
			if($model->where($where)->save($data) == true){
				$this->success('删除成功!');
			}else{
				$this->error('删除失败!');
			}
		}
		elseif(is_array($ids)){
			$ids             = implode(',', $ids);
			$where[$pk_name] = array('in', $ids);

			$model->where($where)->save($data);
			$this->success('批量删除成功!');
		}else{
			$this->error('请选择要删除内容!');
		}
	}
	//从回收站还原
	public function permit($model = ''){
		$id  = $this->_get('id');
		$ids = $this->_post('ids');

		//使用模型
		$model = D($model ? $model : CONTROLLER_NAME);
		// 主键KEY
		$pk_name = $model->getPk();
		$data['is_delete'] = 0;

		if(!is_array($ids) && is_numeric($id)){
			$where[$pk_name] = $id;
			if($model->where($where)->save($data)==true){
				$this->success('还原成功!');
			}else{
				$this->error('还原失败!');
			}
		}
		elseif(is_array($ids)){
			$ids             = implode(',', $ids);
			$where[$pk_name] = array('in', $ids);
			$model->where($where)->save($data);
			$this->success('批量还原成功!');
		}
		else{
			$this->error('请选择要还原记录!');
		}
	}
	//设置状态为启用
	public function set_status_enable($model = ''){
		$id  = $this->_get('id');
		$ids = $this->_post('ids');
		//使用模型
		$model = D($model ? $model : CONTROLLER_NAME);
		// 主键KEY
		$pk_name = $model->getPk();
		$data['status'] = 1;

		if(!is_array($ids) && is_numeric($id)){
			$where[$pk_name] = $id;
			if($model->where($where)->save($data)==true){
				$this->success('启用成功!');
			}else{
				$this->error('启用失败!');
			}
		}
		elseif(is_array($ids)){
			$ids             = implode(',', $ids);
			$where[$pk_name] = array('in', $ids);
			$model->where($where)->save($data);
			$this->success('批量启用成功!');
		}
		else{
			$this->error('请选择要启用记录!');
		}
	}
	//设置状态为禁用
	public function set_status_disable($model = ''){
		$id  = $this->_get('id');
		$ids = $this->_post('ids');

		//使用模型
		$model = D($model ? $model : CONTROLLER_NAME);
		// 主键KEY
		$pk_name = $model->getPk();
		
		$data['status'] = 0;

		if(!is_array($ids) && is_numeric($id)){
			$where[$pk_name] = $id;
			if($model->where($where)->save($data)==true){
				$this->success('禁用成功!');
			}else{
				$this->error('禁用失败!');
			}
		}
		elseif(is_array($ids)){
			$ids             = implode(',', $ids);
			$where[$pk_name] = array('in', $ids);
			$model->where($where)->save($data);
			$this->success('批量禁用成功!');
		}
		else{
			$this->error('请选择要禁用记录!');
		}
	}

	/**
	 * 验证字段内容是否存在
	 * @return [type] [description]
	 */
	public function valid_field($model='',$where=''){
		$keyword = $this->_post('param');//验证内容
		$name    = $this->_post('name');//验证字段
		$fileds  = $this->_get('fileds');//验证其它字段
		$value   = $this->_get('value');//验证其它值
		//使用模型
		$model = D($model?$model:CONTROLLER_NAME);

		$where[$name]       = $keyword;
		$where['is_delete'] = 0;
		if($fileds && $value){
			$fileds = explode(',', $fileds);
			$value  = explode(',', $value);
			foreach ($fileds as $key => $field) {
				$where[$field] = $value[$key];
			}
		}
		// var_dump($where);
		$is_exist = $model->where($where)->find();
		// var_dump($model->getLastSql());

		$data['info']   = $is_exist ? '已存在！' : '可以使用';
		$data['status'] = $is_exist ? 'n' : 'y';
		echo_json($data);
	}
	public function checkbox($model='',$where=''){
		$field = $this->_get('field', '');//字段
		$field = $field ? $field : $this->_get('field_name', '修改字段不能为空！');
		$name  = $this->_get('name', 'name不能为空！');//where 字段
		$id    = $this->_get('id', 'ID不能为空！');//where 值

		$where[$name] = $id;
		//使用模型
		$model = D($model ? $model : CONTROLLER_NAME);

		$value = $model->where($where)->getField($field);

		$data[$field] = $value ? 0 : 1;
		$model->where($where)->save($data);
		
		$this->json_success('设置成功！');
	}
	public function win_info(){
		$id    = $this->_get('id','对不起，ID不能为空');
		$model = D(CONTROLLER_NAME);
		$info  = $model->find($id);

		//整合外部数据
		$set_info = $this->_set_info?$this->_set_info:array();
		$new_info = array_merge($info,$set_info);
		
		$this->assign('info',$new_info);
		$this->display();
	}
}
?>